import QtQuick 2.12
import QtQuick.Extras 1.4
import QtQuick.Controls 2.3
import "storage.js" as Storage

Item {
    id: root1
    width: 850
    height: 580

    //控制两个checkbox
    property bool errorStatu: false
    property bool limiterStatu: false

    property real num_P: 0
    property real minSize:  Math.min(width/850, height/580)
    property color majorColor: "#44fdfd"

    function readCircGau(i_whichChannel,i_circGau)
    {
        i_circGau.circularGaugeValue = 0.01*$sqlMcRecorder.qml_getRecordVal_bystr_toint16(i_whichChannel+i_circGau.element_cnmsgText)
    }

    //处理仪表盘+bar
    signal qmlSN_sqlWriteFinish()
    onQmlSN_sqlWriteFinish: {
//        console.log("->page1 operater start")
        var t_var = Storage.readWhichChannelRunning()
        readCircGau(t_var,circularGauge1)
        circularGauge2.circularGaugeValue = 10*$sqlMcRecorder.qml_getRecordVal_bystr_touint16("灭磁柜电压")/$sqlMcRecorder.qml_getFactor("exc_capacity")
        readCircGau(t_var,circularGauge3)
        readCircGau(t_var,circularGauge4)
        readCircGau(t_var,circularGauge5)
        readCircGau(t_var,circularGauge6)

        circularGauge1.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"机端电压")*0.0001
                *$sqlMcRecorder.qml_getFactor("stator_voltage")
        circularGauge2.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_touint16("灭磁柜电压")*0.1
        circularGauge3.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"机端电流")*0.0001
                *$sqlMcRecorder.qml_getFactor("stator_current")
        circularGauge4.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"励磁电流")*0.0001
                *$sqlMcRecorder.qml_getFactor("exc_current")
        circularGauge5.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"有功功率")*0.0000001
                *$sqlMcRecorder.qml_getFactor("motor_capacity")
        circularGauge6.text_value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16(t_var+"无功功率")*0.0000001
                *$sqlMcRecorder.qml_getFactor("motor_capacity")

        progressBar.value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16("A套控制信号")*180/10000
        progressBar2.value = $sqlMcRecorder.qml_getRecordVal_bystr_toint16("B套控制信号")*180/10000

//        var limiterStatus = false;
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","过励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","欠励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","VF限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","强励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","定子电流限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","过无功限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("A套","调节器故障","最小励磁电流限制")===true) limiterStatus=true

//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","过励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","欠励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","VF限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","强励限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","定子电流限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","过无功限制")===true) limiterStatus=true
//        if($sqlMcRecorder.qml_getBitBool("B套","调节器故障","最小励磁电流限制")===true) limiterStatus=true
//        limiterStatu = limiterStatus
    }

    EXC_Gauge3 {
        id: circularGauge1
        width: parent.width/6
        anchors.topMargin: parent.height/589*20
        anchors.top: parent.top
        element_cnmsgText: qsTr("机端电压")
    }

    EXC_Gauge3 {
        id: circularGauge2
        width: parent.width/6
        anchors.left: circularGauge1.right
        anchors.top: circularGauge1.top
        element_cnmsgText: qsTr("励磁电压")
        element_tipText: "Uf(%)"
    }

    EXC_Gauge3 {
        id: circularGauge3
        width: parent.width/6
        anchors.left: circularGauge2.right
        anchors.top: circularGauge1.top
        element_cnmsgText: qsTr("机端电流")
        element_numsizeText: "A"
        element_tipText: "Ig(%)"
    }

    EXC_Gauge3 {
        id: circularGauge4
        width: parent.width/6
        anchors.left: circularGauge3.right
        anchors.top: circularGauge1.top
        element_cnmsgText: qsTr("励磁电流")
        element_numsizeText: "A"
        element_tipText: "If(%)"
    }

    EXC_Gauge4 {
        id: circularGauge5
        width: parent.width/6
        anchors.left: circularGauge4.right
        anchors.top: circularGauge1.top
        element_cnmsgText: qsTr("有功功率")
        element_numsizeText: "MW"
        element_tipText: "P(%)"
        text_valueLengthAfterPoint:2
        circularGaugeMaximumValue: 100
        circularGaugeMinimumValue: -100
        circularGaugeValue: num_P.toFixed(2)
        circularGaugeHighlightValue: 80
    }

    EXC_Gauge4 {
        id: circularGauge6
        width: parent.width/6
        anchors.left: circularGauge5.right
        anchors.top: circularGauge1.top
        element_cnmsgText: qsTr("无功功率")
        element_numsizeText: "MVar"
        element_tipText: "Q(%)"
        text_valueLengthAfterPoint:2
        circularGaugeMaximumValue: 100
        circularGaugeMinimumValue: -100
        circularGaugeHighlightValue: 80
    }

    Text {
        text: progressBar.value.toFixed(1)+qsTr("° ")
        anchors.verticalCenter: progressBar.verticalCenter
        anchors.left: progressBar.right
        anchors.leftMargin: parent.width/30
        font.pixelSize: 30
        color: majorColor
    }

    ProgressBar {
        id: progressBar
        width: parent.width/2
        height: parent.height/20
        to: 180
        value: 83.33
        anchors.left: parent.left
        anchors.leftMargin: parent.width/3
        anchors.top: circularGauge1.bottom
        anchors.topMargin: parent.height/7
        background: Rectangle {
            implicitWidth: parent.width
            implicitHeight: parent.height
            color: "#C6C6C6"
            radius: 12
        }

        contentItem: Item {
            implicitWidth: parent.width
            implicitHeight: parent.height

            Rectangle {
                width: parent.parent.visualPosition * parent.width
                height: parent.height*0.8
                radius: 10
                anchors.verticalCenter: parent.verticalCenter
                color: majorColor
            }
        }
    }

    Text {
        text:qsTr("A通道触发角度")
        font.bold: true
        font.family: "Verdana"
        anchors.rightMargin: parent.width/20
        anchors.right: progressBar.left
        anchors.verticalCenter: progressBar.verticalCenter
        font.pixelSize: 30
        color: majorColor
    }

    ProgressBar {
        id: progressBar2
        width: parent.width/2
        height: parent.height/20
        to: 180
        value: 83.33
        anchors.left: parent.left
        anchors.leftMargin: parent.width/3
        anchors.top: circularGauge1.bottom
        anchors.topMargin: parent.height/7*2
        background: Rectangle {
            implicitWidth: parent.width
            implicitHeight: parent.height
            color: "#C6C6C6"
            radius: 12
        }

        contentItem: Item {
            implicitWidth: parent.width
            implicitHeight: parent.height

            Rectangle {
                width: parent.parent.visualPosition * parent.width
                height: parent.height*0.8
                radius: 10
                anchors.verticalCenter: parent.verticalCenter
                color: majorColor
            }
        }
    }

    Text {
        text:progressBar2.value.toFixed(1)+qsTr("° ")
        anchors.leftMargin: parent.width/30
        anchors.left: progressBar2.right
        anchors.verticalCenter: progressBar2.verticalCenter
        font.pixelSize: 30
        color: majorColor
    }

    Text {
        color: majorColor
        text:qsTr("B通道触发角度")
        font.bold: true
        font.family: "Verdana"
        anchors.rightMargin: parent.width/20
        anchors.right: progressBar2.left
        anchors.verticalCenter: progressBar2.verticalCenter
        font.pixelSize: 30
    }

    EXC_Normal_CheckBoxSytle {
        id:radioButton
        text: qsTr("故障")
        checked: errorStatu
        textSize: 35*main_screen.minSize
        anchors.left: progressBar2.left
        anchors.topMargin: parent.height/10
        anchors.top: progressBar2.bottom
    }

    EXC_Normal_CheckBoxSytle {
        text: qsTr("限制动作")
        checked: limiterStatu
        anchors.verticalCenter: radioButton.verticalCenter
        textSize: 35*main_screen.minSize
        anchors.leftMargin: parent.width/10
        anchors.left: radioButton.right
    }

}

/*##^##
Designer {
    D{i:0;formeditorZoom:0.5}
}
##^##*/
